/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pieces;

import com.jme3.asset.AssetManager;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

/**
 *
 * @author david
 */
public class Loader {

    /**
     * Loading chessboard and add it to the rootNode.
     * @param assetManager
     * @param rootNode
     * @return Spatial
     */
    public static void loadChessboard(AssetManager assetManager, Node rootNode) {
        Spatial chessboard = assetManager.loadModel("Models/chessboard.j3o");        
        
        rootNode.attachChild(chessboard);
        
        //return chessboard;
    }
    
    /**
     * This static function is loading white pieces.
     * Returns an array of Piece. Contains:
     * -element 0: king;
     * -element 1: queen;
     * -elements 2-3: bishop;
     * -elements 4-5: knight;
     * -element 6-7: rook;
     * -elements 8-15: pawns.
     * Also adds them to the rootNode.
     * @param assetManager application's assetmanager
     * @param rootNode application's rootNode
     * @return Piece array
     */
    public static Piece[] loadWhitePieces(AssetManager assetManager, Node rootNode) {
        Piece[] pieces = new Piece[16];
        
        //king
        pieces[0] = new King();
        pieces[0].spatial = assetManager.loadModel("Models/white_king.j3o");
        pieces[0].spatial.scale(0.22f);
        
        //queen
        pieces[1] = new Queen();
        pieces[1].spatial = assetManager.loadModel("Models/white_queen.j3o");
        pieces[1].spatial.scale(0.22f);
        
        //bishops
        pieces[2] = new Bishop();
        pieces[2].spatial = assetManager.loadModel("Models/white_bishop.j3o");
        pieces[2].spatial.scale(0.3f);
        pieces[3] = new Bishop();
        pieces[3].spatial = assetManager.loadModel("Models/white_bishop.j3o");
        pieces[3].spatial.scale(0.3f);
        
        //knights
        pieces[4] = new Knight();
        pieces[4].spatial = assetManager.loadModel("Models/white_knight.j3o");
        pieces[4].spatial.scale(0.3f);
        pieces[5] = new Knight();
        pieces[5].spatial = assetManager.loadModel("Models/white_knight.j3o");
        pieces[5].spatial.scale(0.3f);
        
        //rooks
        pieces[6] = new Rook();        
        pieces[6].spatial = assetManager.loadModel("Models/white_rook.j3o");
        pieces[6].spatial.scale(0.3f);
        pieces[7] = new Rook();
        pieces[7].spatial = assetManager.loadModel("Models/white_rook.j3o");
        pieces[7].spatial.scale(0.3f);
        
        //pawns
        for(int i = 8; i < pieces.length; i++) {
            pieces[i] = new Pawn();
            pieces[i].spatial = assetManager.loadModel("Models/white_pawn.j3o");
            pieces[i].spatial.scale(0.25f);
        }
        
        //add them to the rootNode
        for (int i = 0; i < pieces.length; i++) {
            rootNode.attachChild(pieces[i].spatial);   
        }
        
        return pieces;
    }
    
    /**
     * This static function is loading black pieces.
     * Returns an array of Piece. Contains:
     * -element 0: king;
     * -element 1: queen;
     * -elements 2-3: bishop;
     * -elements 4-5: knight;
     * -element 6-7: rook;
     * -elements 8-15: pawns.
     * Also adds them to the rootNode.
     * @param assetManager application's assetmanager
     * @param rootNode application's rootNode
     * @return Piece array
     */
    public static Piece[] loadBlackPieces(AssetManager assetManager, Node rootNode) {
        Piece[] pieces = new Piece[16];
        
        //king
        pieces[0] = new King();
        pieces[0].spatial = assetManager.loadModel("Models/black_king.j3o");
        pieces[0].spatial.scale(0.22f);
        
        //queen
        pieces[1] = new Queen();
        pieces[1].spatial = assetManager.loadModel("Models/black_queen.j3o");
        pieces[1].spatial.scale(0.22f);
        
        //bishops
        pieces[2] = new Bishop();
        pieces[2].spatial = assetManager.loadModel("Models/black_bishop.j3o");
        pieces[2].spatial.scale(0.3f);
        pieces[3] = new Bishop();
        pieces[3].spatial = assetManager.loadModel("Models/black_bishop.j3o");
        pieces[3].spatial.scale(0.3f);
        
        //knights
        pieces[4] = new Knight();
        pieces[4].spatial = assetManager.loadModel("Models/black_knight.j3o");
        pieces[4].spatial.scale(0.3f);
        pieces[5] = new Knight();
        pieces[5].spatial = assetManager.loadModel("Models/black_knight.j3o");
        pieces[5].spatial.scale(0.3f);
        
        //rooks
        pieces[6] = new Rook();
        pieces[6].spatial = assetManager.loadModel("Models/black_rook.j3o");
        pieces[6].spatial.scale(0.3f);
        pieces[7] = new Rook();
        pieces[7].spatial = assetManager.loadModel("Models/black_rook.j3o");
        pieces[7].spatial.scale(0.3f);
        
        //pawns
        for(int i = 8; i < pieces.length; i++) {
            pieces[i] = new Pawn();
            pieces[i].spatial = assetManager.loadModel("Models/black_pawn.j3o");
            pieces[i].spatial.scale(0.25f);
        }
        
        //add them to the rootNode
        for (int i = 0; i < pieces.length; i++) {            
            rootNode.attachChild(pieces[i].spatial);            
        }
        
        return pieces;
    }
}
